set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
/* *******************************************************************
** DATE :
** Writer :
** Memo :
******************************************************************** */
CREATE PROCEDURE [dbo].[TSP_Advertise_Modify]
(
	@IsTransaction	tinyint			= 0
,	@ErrorCode		int				= 0		OUTPUT
,	@ErrorMessage	nvarchar( 1000 )= ''	OUTPUT

,	@n4AdvertiseNo	int	
,	@strTitle	nvarchar(200)	
,	@strListTitle	nvarchar(200)	= NULL	
,	@strContent	nvarchar(4000)	= NULL	
,	@strLink	varchar(300)	= NULL	
,	@strImageURL	varchar(200)	= NULL	
,	@strThumbURL	varchar(200)	= NULL	
,	@n1MoveType	tinyint	= NULL	
,	@strMovieURL	varchar(300)	= NULL	
,	@strHTML	varchar(1000)	= NULL	
,	@strFlashURL	varchar(300)	= NULL	
,	@strManagerName	nvarchar(100)	
,	@strImage2URL	varchar(200)	= NULL
,	@strImage3URL	varchar(200)	= NULL
,	@strImage4URL	varchar(200)	= NULL
,	@strImage5URL	varchar(200)	= NULL
)
as
Set NOCOUNT ON

-- Frk Default Value
DECLARE @FrkDateNow DateTime
DECLARE @FrkRowCount int
DECLARE @FrkTranCount int
DECLARE @FrkErrorCode int
DECLARE @FrkErrorMessage nvarchar( 1000 )
Set @FrkDateNow = GetDate()
set @FrkTranCount = @@TRANCOUNT
-- Frk Check


If ( @IsTransaction = 0 )
Begin
	If ( @FrkTranCount < 1 )
	Begin
		Set @FrkErrorCode = -1
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Else If ( @FrkTranCount > 1 )
	Begin
		Set @FrkErrorCode = -2
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
End
Else
Begin
	If ( @FrkTranCount <> 0 )
	Begin
		Set @FrkErrorCode = -3
		Set @FrkErrorMessage = 'Transaction.'
		goto ERROR
	End
	Begin Tran
End

-- Implementation


UPDATE
	dbo.TB_Advertise
SET
	strTitle = IsNull( @strTitle, strTitle )
,	strListTitle = IsNull( @strListTitle, strListTitle )
,	strContent = IsNull( @strContent, strContent )
,	strLink = IsNull( @strLink, strLink )
,	strImageURL = IsNull( @strImageURL, strImageURL )
,	strThumbURL = IsNull( @strThumbURL, strThumbURL )
,	n1MoveType = IsNull( @n1MoveType, n1MoveType )
,	strMovieURL = IsNull( @strMovieURL, strMovieURL )
,	strHTML = IsNull( @strHTML, strHTML )
,	strFlashURL = IsNull( @strFlashURL, strFlashURL )
,	dtModifyDate = @FrkDateNow
,	strManagerName = IsNull( @strManagerName, strManagerName )

,	strImage2URL = IsNull( @strImage2URL, strImage2URL )
,	strImage3URL = IsNull( @strImage3URL, strImage3URL )
,	strImage4URL = IsNull( @strImage4URL, strImage4URL )
,	strImage5URL = IsNull( @strImage5URL, strImage5URL )
WHERE
	n4AdvertiseNo = @n4AdvertiseNo


-- Frk Error Check
SELECT
	@FrkErrorCode = @@ERROR
,	@FrkRowCount = @@RowCount

-- End

COMPLETE:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Commit Tran
		End
	End
	SET @ErrorCode = 0
	SET @ErrorMessage = ''
	return 0
ERROR:
	If ( @IsTransaction <> 0 )
	Begin
		If ( @@TRANCOUNT = 1 )
		Begin
			Rollback Tran
		End
	End
	SET @ErrorCode = @FrkErrorCode
	SET @ErrorMessage = @FrkErrorMessage
	return @FrkErrorCode
